<?php
namespace Home\Controller;
use Think\Controller;
class AdvmodelController extends Controller {

	public function index(){
		//分表演示
		C('DB_PREFIX', 'adv_');
		$article = D('AdvArticle');
		$article->emptyTable();//清空多表
		for ($i=0; $i < 3; $i++) {
			//获取最新的id供分表识别表名所用
			$id = $article->init()->max('id');
			$id = intval($id);
			$targetId = $id+1;

			$this->show('准备插入的数据：');
			$data = array('title'=>'标题'.$key, 'content'=>'内容'.$key, 'time'=>time(), 'id'=>$targetId);
			dump($data);
			$advModel = $article->init($data);
			$result = $advModel->add($data);
			if($result){
				$this->show('插入数据后的id为：'.$result);
			}else{
				$this->show('插入id为'.$targetId.'的数据失败,失败原因：'.$advModel->getError());
			}
			$this->show('<br><br>');
		}
		$allData = $article->init()->select();
		var_dump($allData);
		var_dump($allData, 'object');
	}
}